
LESS_COEF = 0.5

Anal = {
   accu = 0,
   money_start = 0,
   money = 0,
   day_total = 0,
   day = 0,
   max = 0,
   min = 0,
   current = 0,
   les = 0,
   croissant = false,
   all = {},
   nb_action = 0,
   _update = {updateCurrent, updateMoney, updateDay, updateMax, updateMin, updateLes}
}


function Anal:updateCurrent(money)
   table.insert(Anal.all, money)
   Anal.current = money
end

function Anal:updateMoney(money)
   Anal.money = Anal.money
end

function Anal:updateDay()
   Anal.day = Anal.day - 1
end

function Anal:updateMax(money)
   if Anal.max < money then
      Anal.max = money
   end
end

function Anal:updateMin(money)
   if Anal.day + 1 == Anal.day_total then
      Anal.min = money
   elseif Anal.min > money then
      Anal.min = money
   end
end

function Anal:updateLes(money)
   local old = Anal.les
   if Anal.day + 1 == Anal.day_total then
      Anal.les = money
   else
      Anal.les = money * LESS_COEF + (1 - LESS_COEF) * Anal.les
   end
   Anal.croissant = Anal.les >= old
end


function print()
   log:write(Anal.accu, "|", Anal.current, "|", Anal.money, " ", Anal.day," ", Anal.max," ", Anal.min," ", Anal.les, " ", tostring(Anal.croissant), "\n")
end

function Anal:init(money, day)
   self.money_start = money
   self.money = money
   self.day_total = day
   self.day = day
end

function Anal:update(money)
   self.accu = self.accu + 1


   Anal:updateCurrent(money)
   Anal:updateDay(money)   
   Anal:updateMoney(money)
   Anal:updateMax(money)
   Anal:updateMin(money)
   Anal:updateLes(money)
end
